<template>
  <div>
    <div class="login-content">
      <div class="login-form-box">
        <div class="login-form-logo">
          <h1>{{validateData.enterpriseName}}管理员</h1>
          <h2 v-if="validateData.validateUrlStatus==1&&(!validateData.phoneIfVerify || !validateData.mailIfVerify)">{{type=='phone'?'请您通过手机发送验证码，进行身份验证，感谢您的配合！':'请点击验证按钮进行验证，感谢您的配合！'}}</h2>
        </div>
        <!-- 短信验证 -->
        <div v-if="type=='phone'">
          <!-- validateUrlStatus 1未失效 0已失效     phoneIfVerify 0未验证  1已验证 -->
          <div v-if="validateData.validateUrlStatus==1 && !validateData.phoneIfVerify">
            <el-form ref="dialogForm" :model="baseInfo" class="login-form" >
              <el-form-item class="login-form-item" prop="identifier">
                <img class="login-form-img" src="../../assets/img/icon_3.png"/>
                <el-input v-model="baseInfo.identifier" maxlength="11" name="phone" class="login-item-input" placeholder="手机号码"/>
              </el-form-item>
              <el-form-item class="login-form-item">
                <img class="login-form-img" src="../../assets/img/icon_4.png"/>
                <el-input v-model="baseInfo.code" name="code" class="login-item-input" placeholder="6位数验证码"/>
                <span class="login-form-code" v-if="computeTime == 0" @click="handleGetCode()">获取验证码</span>
                <span class="login-form-time" v-else>{{ computeTime }} s</span>
              </el-form-item>
              <el-button class="login-form-btn" type="primary" @click="onSubmit()">验证</el-button>
            </el-form>
          </div>
          <div v-if="!validateData.validateUrlStatus" class="verification-text" >链接已过期，请重新发送链接进行验证!</div>
          <div v-if="validateData.validateUrlStatus==1&&validateData.phoneIfVerify==1" class="verification-text" >您的手机号已经通过验证，感谢您的配合!</div>
        </div>
        <!-- 邮箱验证 -->
        <div class="emails-box" v-if="type=='mail'">
          <el-button v-if="validateData.validateUrlStatus==1&&!validateData.mailIfVerify" class="login-form-email-btn" type="primary" @click="onSubmit()">验 证</el-button>
          <div v-if="!validateData.validateUrlStatus" class="verification-text" >链接已过期，请重新发送链接进行验证!</div>
          <div v-if="validateData.validateUrlStatus==1&&validateData.mailIfVerify==1" class="verification-text" >您的邮箱已经通过验证，感谢您的配合!</div>
        </div>
      </div>
    </div>
      
  </div>
</template>

<script>
import * as Port from "../../api/index";
export default {
  data() {
    return {
      type:'',
      enterpriseid:'',
      computeTime: 0, // 计时的时间
      btnLock: false,
      baseInfo: {
        identifier: '',
        code: ''
      },
      validateData:{},
    };
  },
  created() {
    this.type = this.$route.query.type
    this.enterpriseid = this.$route.query.id 
    this.getEnterpriseDetaile()
  },
  methods: {
    async getEnterpriseDetaile(){
      let res = await Port.enterpriseDetaile({
        authenticationRecordKey:this.enterpriseid
      }) 
      this.validateData = res
    },
    handleGetCode(phone) {
      let tel = phone || this.baseInfo.identifier;
      window.yj.getSmsCode(tel).then(data => {
        if(phone){
          return
        }
        // 启动倒计时
        this.computeTime = 30;
        this.intervalId = setInterval(() => {
          this.computeTime -= 1;
          if (this.computeTime <= 0) {
            // 停止计时
            clearInterval(this.intervalId);
          }
        }, 1000);
      })
      .catch(error => {
        error.message && this.$message.error(error.message);
      });
    },
  
    async onSubmit() {
      let params = {
        authenticationRecordKey:this.enterpriseid
      }
      if(this.type=='phone'){
        if(!this.baseInfo.identifier || !this.baseInfo.identifier){
          this.$message.error('请完成填写信息！')
          return
        }
        params = Object.assign(params,this.baseInfo)
      }
      await Port.apiVerifyedSmsEmail(params)
      this.getEnterpriseDetaile()
      this.$message.success('验证成功！')
    },
  },
};
</script>

<style lang="scss" >

.login-content {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  width: 100%;
  min-height: 100%;
  background: #fff;
  background-size: cover;
  display: flex;
  justify-content: center;
  .login-form-box {
    position: fixed;
    top: 45%;
    -webkit-transform: translateY(-50%);
    -moz-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    -o-transform: translateY(-50%);
    transform: translateY(-50%);
    .verification-text{
      text-align: center;
      font-size: 16px;
      font-weight: bold;
      margin-top:20px;
      width: 300px;
    }
  }
  .emails-box{
    display: flex;
    justify-content: center;
    .login-form-email-btn{
      margin-top:30px;
      width:280px;
      text-align: center;
    }
  }
  
  .login-form-logo {
    h1 {
      line-height: 38px;
      font-size: 20px;
      font-weight: 500;
      padding-bottom:10px;
    }
    h2{
      text-align: left;
      padding-bottom: 15px;
      width: 300px;
    }
  }


  .login-form {
    background: #F4F4F4!important;
    width: 18vw;
    min-width: 300px;
    padding: 22px 2.1vw;
    background: rgba(255, 255, 255, 1);
    border-radius: 8px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
    .login-form-btn {
      width: 100%;
    }
    .login-form-item {
      .el-form-item__content {
        border-bottom: 1px solid #cccccc;
        display: flex;
        align-items: center;
      }
      .login-form-img {
        width: 21px;
        height: 21px;
      }
      .login-item-input {
        flex: 1;
        .el-input__inner {
          height: 20px;
          line-height: 20px;
          border: 0px;
          color: #000000;
          font-size: 16px;
        }
      }
      .login-form-code {
        font-size: 14px;
        height: 20px;
        line-height: 20px;
        font-size: 14px;
        font-weight: 400;
        color: #409eff;
        cursor: pointer;
      }
      .login-form-time {
        color: #606266;
        cursor: default;
        padding: 0 20px;
        pointer-events: none;
      }
    }
  }
}
.ban-click {
  pointer-events: none;
  background: #ccc;
  border-color: #ccc;
}
.login-dialog-center {
  .el-select {
    padding: 30px 0;
    width: 100%;
  }
}
</style>
